
#include <stdlib.h>
#include <highgui.h>
#include "utility.h"
#include "qr-image.h"

QRImage* qr_image_new(const char* filename)
{
	QRImage* qr_image;

	if(NULL == filename)
	{
		RES_NULL("Argument is invalid.");
	}

	qr_image = (QRImage*)malloc(sizeof(QRImage));
	if(NULL == qr_image)
	{
		RES_NULL("Invoke malloc error.");
	}
	qr_image->_source = cvLoadImage(filename, 1);
	if(NULL == qr_image->_source)
	{
		free(qr_image);
		RES_NULL("Invoke cvLoadImage error.");
	}
	qr_image->_gray_image = NULL;
	return qr_image;
}

void qr_image_destroy(QRImage* qr_image)
{
	if(qr_image != NULL)
	{
		if(qr_image->_source != NULL)
		{
			cvReleaseImage(&(qr_image->_source));
		}
		if(qr_image->_gray_image != NULL)
		{
			cvReleaseImage(&(qr_image->_gray_image));
		}
		free(qr_image);
	}
}

